package io.gitee.devaper.starlight.security.common

import com.google.common.collect.ImmutableList
import jakarta.servlet.http.*
import org.springframework.security.core.*
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy
import org.springframework.util.Assert

class SessionAuthenticationStrategyComposite(strategies: Collection<SessionAuthenticationStrategy>) : SessionAuthenticationStrategy {

    private val strategies: List<SessionAuthenticationStrategy>

    init {
        Assert.notEmpty(strategies, "strategies cannot be null")
        this.strategies = ImmutableList.copyOf(strategies)
    }

    override fun onAuthentication(
        authentication: Authentication,
        request: HttpServletRequest,
        response: HttpServletResponse
    ) {
        for (strategy in strategies) {
            strategy.onAuthentication(authentication, request, response)
        }
    }

    constructor(vararg strategies: SessionAuthenticationStrategy): this(ImmutableList.copyOf(strategies))

}